package com.hjqjl.whdemo.feature.feature0.ui.activity.custom;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.view.View;

import androidx.appcompat.app.AlertDialog;

import com.blankj.utilcode.util.ToastUtils;
import com.hjqjl.whdemo.R;
import com.hjqjl.whdemo.base.BaseActivity;
import com.hjqjl.whdemo.databinding.ActivityDialogBinding;
import com.hjqjl.whdemo.dialog.DialogBottom;
import com.hjqjl.whdemo.dialog.DialogCustom;
import com.hjqjl.whdemo.dialog.DialogLoading;
import com.hjqjl.whdemo.dialog.DialogTop;

public class DialogActivity extends BaseActivity {
    public static void actionStart(Context context) {
        Intent intent = new Intent(context, DialogActivity.class);
        context.startActivity(intent);
    }

    private ActivityDialogBinding binding;

    @Override
    protected void initData() {
        binding = ActivityDialogBinding.inflate(getLayoutInflater());
        View view = binding.getRoot();
        setContentView(view);
    }

    @Override
    protected void processLogic() {
        binding.btnTopdialog.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DialogTop.show(pActivity);
            }
        });

        binding.btnCustomdialog.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DialogCustom.show(pActivity, "我是自定义title", "我是内容--我是自定义的Dialog", new DialogCustom.OnClickMyListener() {
                    @Override
                    public void onMyClick(Dialog dialog) {
                        dialog.dismiss();
                    }
                });
            }
        });

        binding.btnDialogLoading.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DialogLoading.showLoading(pActivity, "加载中。。。", true);
            }
        });

        binding.btnBottomdialog.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DialogBottom.show(pActivity, new DialogBottom.OnClickMyListener() {
                    @Override
                    public void onMyClick(Dialog dialog) {
                        dialog.dismiss();
                        ToastUtils.showShort("我是从activity关闭的");
                    }
                });
            }
        });

        binding.btnAlertDialog.setOnClickListener(v -> {
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle("系统弹窗AlertDialog");
            builder.setMessage("Message这是一个普通对话框");
            builder.setIcon(R.mipmap.ic_launcher);
            builder.setCancelable(true);            //点击对话框以外的区域是否让对话框消失
            builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
            AlertDialog dialog = builder.create();//创建AlertDialog对象
            dialog.show();
        });
    }
}
